package cn.szzsi.common.model;

import cn.szzsi.common.model.base.BaseTocash;

import java.util.Date;
import java.util.List;

/**
 * Created by yuanzhneg on 2016/11/25.
 */
//@TableBind(tableName = "b_tocash", pkName = "id")
public class Tocash extends BaseTocash<Tocash> {
    public static final Tocash dao=new Tocash().dao();

    // 会员提现状态（提现中,提现成功）
    public enum ToCashingStatus {
        inToCashing,toCashingSuccess,reject
    };

    public ToCashingStatus getStatusValue(){
        return ToCashingStatus.values()[getInt("status")];
    }

    public TocashBank getByCashingBankId(){
        return TocashBank.dao.findById(getInt("bankId"));
    }

    public void init(){
        Integer bankId = this.getInt("bankId");
        TocashBank tcg = TocashBank.dao.findById(bankId);
        this.put("name",tcg == null?"":tcg.getStr("name"));
        this.put("cardNumber",tcg == null?"":tcg.getStr("cardNumber"));
        this.put("cardCount",tcg == null?"":tcg.getStr("cardCount"));
        this.put("cardAddress",tcg == null?"":tcg.getStr("cardAddress"));
    }

    public static List<Tocash> getByMemberId(String member_id){
        return dao.find("select * from mall_tocash where member_id=? order by createDate desc ",member_id);
    }

    /**
     * 查询会员最后最后一次提现记录
     * @param member_id
     * @return
     */
    public static Tocash getLastByMemberId(String member_id){
        return dao.findFirst("select * from mall_tocash where member_id=? order by createDate desc limit 1",member_id);
    }

    /**
     *
     * @param member_id 会员id
     * @param shopId
     * @param bankId 银行卡id
     * @param bankType 银行卡类型
     * @param cashAmount 提现金额
     */
    public static final void saveToCashing(String member_id, String shopId, String bankId,String bankType, String cashAmount){
        Tocash toCashing=new Tocash();
        toCashing.set("cashAmount",cashAmount);
        toCashing.set("member_id",member_id);
        toCashing.set("uid",shopId);
        toCashing.set("bankId",bankId);
        toCashing.setBankType(bankType);
        toCashing.set("createDate",new Date());
        toCashing.set("status", ToCashingStatus.inToCashing.ordinal());
        toCashing.save();
    }

}
